
export const getCurrentTab = async () => {

    let queryOptions = { active: true, lastFocusedWindow: true };
    // `tab` will either be a `tabs.Tab` instance or `undefined`.
    let [tab] = await browser.tabs.query(queryOptions);
    return tab;
}

export const sendMessage = async (message: any) => {
    return await browser.runtime.sendMessage(message)
}

export const cookiesGet = async (name : string, url : string) => {
	if (!url) {
		url = (await getCurrentTab()).url as string
	}
	return await browser.cookies.get({name, url})
}

export const localStorage = ()=>{
    return browser.storage.local
}

export const localSave = async (key: string, value: any)=>{
    let data = await browser.storage.local.get([key]);
    if (!data) {
        data = {}
    }
    if (!data[key]) {
        data[key] = {}
    }
    Object.assign(data[key], value)
    browser.storage.local.set(data)
}